<?php

namespace App\Http\Controllers\Web\Seller;

use App\ConstDir\ErrorConst;
use App\Http\Controllers\Web\BaseController;

use App\Repository\Repositories\Interfaces\OrdersRepository;
use App\Repository\Repositories\Interfaces\ShopCategoriesRepository;
use App\Services\Api\KuaiDi100;
use Illuminate\Http\Request;

/**
 * 订单管理控制器
 *
 * @package App\Http\Controllers\Backend
 */
class ShopCategoriesController extends BaseController
{
    /**
     * @var
     */
    protected $shopcategories;
    protected $shop_id;
    protected $user_id;

    public function __construct(ShopCategoriesRepository $shopcategories)
    {
        parent::__construct();
        $this->shopcategories = $shopcategories;
        $this->user_id = array_get($this->user, 'id');
        $this->shop_id = array_get($this->user, 'shop_id');

        //用户只能操作自身所属数据
        $this->shopcategories->scopeQuery(function ($query) {
            return $query->where('shop_id', $this->shop_id);
        });
    }

    public function index()
    {
        $res = $this->shopcategories->paginate($this->perPage);
        return $this->success(ErrorConst::SUCCESS_CODE_MSG, $res, true);
    }


    public function store(Request $request)
    {
        $this->validate($request, [
            'name' => 'required'
        ]);
        $data = $request->all();
        $data['shop_id']=$this->shop_id;

        $ret = $this->shopcategories->create($data);

        return $this->noDataReturn($ret ? true : false);
    }

    public function update(Request $request, $id)
    {
        $this->validate($request, [
            'name' => 'required',
        ]);
        $data = $request->all();
        $ret = $this->shopcategories->update($data, $id);
        return $this->noDataReturn($ret ? true : false);
    }

    public function delete($id)
    {

        $ret = $this->shopcategories->delete($id);

        return $this->noDataReturn($ret ? true : false);
    }


}
